# -*- coding: utf-8 -*-
from django.db.models import permalink, signals
from google.appengine.ext import db
from ragendja.dbutils import cleanup_relations

class Category(db.Model):
    slug = db.StringProperty(required=True)
    title = db.StringProperty(required=True)
    summary = db.TextProperty()
    position = db.IntegerProperty(required=True)
    
    def __unicode__(self):
        return self.title
    
    class Meta:
        ordering = ['-position']            
    
class Tag(db.Model):
    name = db.StringProperty(required=True)
    category = db.ReferenceProperty(Category, collection_name='tags')
    
    def __unicode__(self):
        return self.name
    
    class Meta:
        ordering = ['-name']
        
class Album(db.Model):
    slug = db.StringProperty(required=True)
    title = db.StringProperty(required=True)    
    published = db.DateTimeProperty(required=True)
    link = db.LinkProperty(required=True)
    thumbnail = db.LinkProperty()
    albumid = db.StringProperty(required=True)
    summary = db.TextProperty()
    
    def __unicode__(self):
        return self.title
    
    class Meta:
        ordering = ['-published']            
    
class Photo(db.Model):
    slug = db.StringProperty(required=True)
    title = db.StringProperty(required=True)
    published = db.DateTimeProperty(required=True)
    link = db.LinkProperty(required=True)
    thumbnail = db.LinkProperty()
    album = db.ReferenceProperty(Album, required=True, collection_name='photos')
    photoid = db.StringProperty(required=True)
    width = db.IntegerProperty()
    height = db.IntegerProperty()
    summary = db.TextProperty()
    tags = db.StringListProperty()
    
    def __unicode__(self):
        return self.title
    
    class Meta:
        ordering = ['-published']